package com.example.aliyun.plus.sync;

class MyThread implements Runnable{
    private int ticket = 10; // 票总数


    @Override
    public void run() {
        while (1 == 1){
            if (this.ticket > 0){
                try {
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() +"  卖票--------> " + this.ticket--);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                break;
            }
        }
    }
}

/**
 * 线程同步问题的引出
 */
public class ThreadSyncProblem {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        Thread threadA = new Thread(myThread, "票贩子A");
        Thread threadB = new Thread(myThread, "票贩子B");
        Thread threadC = new Thread(myThread, "票贩子C");
        threadA.start();
        threadB.start();
        threadC.start();
    }
}
